# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import csv
from itemadapter import ItemAdapter


class DoubanPipeline:
    def open_spider(self,spider):
        self.fp = open('排行.csv', 'w', encoding='utf-8-sig', newline='')
        self.writer = csv.writer(self.fp)
        self.writer.writerow(['电影名称', '演员信息', '评价', '评分'])

    def process_item(self, item, spider):
        row = [item['name'], item['info'], item['introduce'], item['score']]
        self.writer.writerow(row)
        return item

    def close_spider(self,spider):
        self.fp.close()
